﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using System.Text;
#if UNITY_EDITOR
using UnityEditor;
#endif 

// **********************************************************************
// Copyright (C) XM
// Author: 赵思佳
// Date: 2019-01-04
// Desc: 
// **********************************************************************
namespace SpaceDFramework
{
    public class Exporter
    {
#if UNITY_EDITOR
        public static bool ExportPackage(ref string exportPath, string name, string extention)
        {
            var path = EditorUtility.SaveFilePanel("导出unitypackage", exportPath, name, "unitypackage");
            if (path == "")
                return false;
            var assetPathNames = new string[Selection.objects.Length];
            CommonUtil.LogFormat("Select {0} object", Selection.objects.Length);
            for (var i = 0; i < assetPathNames.Length; i++)
            {
                assetPathNames[i] = AssetDatabase.GetAssetPath(Selection.objects[i]);
                CommonUtil.LogFormat("AssetPath {0} name is {1}", i,assetPathNames[i]);
            }
            assetPathNames = AssetDatabase.GetDependencies(assetPathNames);
            AssetDatabase.ExportPackage(assetPathNames, path, ExportPackageOptions.Recurse);
            exportPath = Path.GetDirectoryName(path);
            return true;
        }
#endif        

        public static string GenerateUnityPackageName()
        {
            string gen_name = PlayerSettings.productName + DateTime.Now.ToString("yyyyMMdd_HH");
            CommonUtil.Log(gen_name);
            return gen_name;
        }
        /// <summary>
        /// 生成版本号。
        /// </summary>
        /// <returns></returns>
        public static string GenerateUnityPackageNameVersion()
        {
            StringBuilder version = new StringBuilder(PlayerSettings.productName);
            version.Append("_v").Append(PlayerSettings.bundleVersion.ToString());
            return version.ToString();
        }
      
    }
}
